package com.cxyzy.colorpickerbardemo

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.cxyzy.colorpickerbar.ColorPickerBar.ColorPickerClickListener
import kotlinx.android.synthetic.main.activity_main.*


class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
            initColorPicker()
    }

    private fun initColorPicker() {
        //设置可选颜色数量，采用色值字符串
        //        colorPickerBar.init("#d71345", "#bed742", "#4e72b8", "#9b95c9", "#45b97c")
        //设置可选颜色数量，采用颜色资源定义
        colorPickerBar.init(
            R.color.color1,
            R.color.color2,
            R.color.color3,
            R.color.color4,
            R.color.color5
        )
        //色值默认选中项
        colorPickerBar.selectItem(1)
        //        colorPickerBar.selectItemByColor(ContextCompat.getColor(this, R.color.color2))
        //设置回调
        colorPickerBar.colorPickerClickListener = object : ColorPickerClickListener {
            override fun onClick(selectedColor: Int) {
                val hexColor = String.format("#%06X", 0xFFFFFF and selectedColor)
                Toast.makeText(this@MainActivity, hexColor, Toast.LENGTH_SHORT).show()
            }
        }
    }


}
